#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2021-present, sun-shine cloud, Inc.
# All rights reserved
# Author：  xiaobo
# Date：    2021-04-13
# 公共的函数
import datetime
import sys
import os
import json

def retInfo(id, ossUrl, info, wtime):

    ret = {}
    ret["code"] = 0
    ret["_id"] = id
    ret["ossUrl"] = ossUrl
    ret["time"] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    ret["work_time"] = wtime
    ret["info"] = info
    return json.dumps(ret,ensure_ascii=False)

def retError(id, ossUrl, info, wtime):

    ret = {}
    ret["code"] = -1
    ret["_id"] = id
    ret["ossUrl"] = ossUrl
    ret["time"] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    ret["work_time"] = wtime
    ret["info"] = info
    return json.dumps(ret,ensure_ascii=False)

#获取程序的当前路径
def get_current_path():
        paths = sys.path
        current_file = os.path.basename(__file__)
        for path in paths:
            try:
                if current_file in os.listdir(path):
                    current_path = path
                    return current_path
            except (FileExistsError,FileNotFoundError) as e:
                print(e)